package com.zhaoxi.project.wms.service.impl;

import java.util.List;

import com.zhaoxi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

import com.zhaoxi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.zhaoxi.project.wms.mapper.WmsGoodsStockCheckMapper;
import com.zhaoxi.project.wms.domain.WmsGoodsStockCheck;

/**
 * 仓储盘点Service业务层处理
 *
 * @author zhaoxi
 * @date 2023-08-25
 */
@Service
public class WmsGoodsStockCheckServiceImpl {
    @Autowired
    private WmsGoodsStockCheckMapper wmsGoodsStockCheckMapper;

    /**
     * 查询仓储盘点
     *
     * @param id 仓储盘点主键
     * @return 仓储盘点
     */

    public WmsGoodsStockCheck selectWmsGoodsStockCheckById(Long id) {
        return wmsGoodsStockCheckMapper.selectWmsGoodsStockCheckById(id);
    }

    /**
     * 查询仓储盘点列表
     *
     * @param wmsGoodsStockCheck 仓储盘点
     * @return 仓储盘点
     */

    public List<WmsGoodsStockCheck> selectWmsGoodsStockCheckList(WmsGoodsStockCheck wmsGoodsStockCheck) {
        return wmsGoodsStockCheckMapper.selectWmsGoodsStockCheckList(wmsGoodsStockCheck);
    }

    /**
     * 新增仓储盘点
     *
     * @param wmsGoodsStockCheck 仓储盘点
     * @return 结果
     */
    @Transactional

    public int insertWmsGoodsStockCheck(WmsGoodsStockCheck wmsGoodsStockCheck) {
        wmsGoodsStockCheck.setCreateTime(DateUtils.getNowDate());
        int rows = wmsGoodsStockCheckMapper.insertWmsGoodsStockCheck(wmsGoodsStockCheck);
//        insertWmsGoodsStockCheckLine(wmsGoodsStockCheck);
        return rows;
    }

    /**
     * 修改仓储盘点
     *
     * @param wmsGoodsStockCheck 仓储盘点
     * @return 结果
     */
    @Transactional

    public int updateWmsGoodsStockCheck(WmsGoodsStockCheck wmsGoodsStockCheck) {
        wmsGoodsStockCheck.setUpdateTime(DateUtils.getNowDate());
        wmsGoodsStockCheckMapper.deleteWmsGoodsStockCheckLineById(wmsGoodsStockCheck.getId());
//        insertWmsGoodsStockCheckLine(wmsGoodsStockCheck);
        return wmsGoodsStockCheckMapper.updateWmsGoodsStockCheck(wmsGoodsStockCheck);
    }

    /**
     * 批量删除仓储盘点
     *
     * @param ids 需要删除的仓储盘点主键
     * @return 结果
     */
    @Transactional

    public int deleteWmsGoodsStockCheckByIds(Long[] ids) {
        wmsGoodsStockCheckMapper.deleteWmsGoodsStockCheckLineByIds(ids);
        return wmsGoodsStockCheckMapper.deleteWmsGoodsStockCheckByIds(ids);
    }

    /**
     * 删除仓储盘点信息
     *
     * @param id 仓储盘点主键
     * @return 结果
     */
    @Transactional

    public int deleteWmsGoodsStockCheckById(Long id) {
        wmsGoodsStockCheckMapper.deleteWmsGoodsStockCheckLineById(id);
        return wmsGoodsStockCheckMapper.deleteWmsGoodsStockCheckById(id);
    }

    /**
     * 新增库存盘点信息
     *
     * @param wmsGoodsStockCheck 仓储盘点对象
    public void insertWmsGoodsStockCheckLine(WmsGoodsStockCheck wmsGoodsStockCheck) {
        List<WmsGoodsStockCheckLine> wmsGoodsStockCheckLineList = wmsGoodsStockCheck.getWmsGoodsStockCheckLineList();
        Long id = wmsGoodsStockCheck.getId();
        if (StringUtils.isNotNull(wmsGoodsStockCheckLineList)) {
            List<WmsGoodsStockCheckLine> list = new ArrayList<WmsGoodsStockCheckLine>();
            for (WmsGoodsStockCheckLine wmsGoodsStockCheckLine : wmsGoodsStockCheckLineList) {
                wmsGoodsStockCheckLine.setId(id);
                list.add(wmsGoodsStockCheckLine);
            }
            if (list.size() > 0) {
                wmsGoodsStockCheckMapper.batchWmsGoodsStockCheckLine(list);
            }
        }
    }
     */
}
